package com.millstein.realtime.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class RedisUtil {

    static {
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxTotal(100);
        config.setMaxIdle(10);
        config.setMaxWaitMillis(10 * 1000);
        config.setMinIdle(2);
        config.setTestOnCreate(true);
        config.setTestOnBorrow(true);
        config.setTestOnReturn(true);

        jedisPool = new JedisPool(config, "hadoop102", 6379);
    }

    private static final JedisPool jedisPool;

    /**
     * 获取操作redis的客户端
     * @return
     */
    public static Jedis getRedisClient() {
        Jedis jedis = jedisPool.getResource();
        jedis.select(1);
        return jedis;
    }
}
